diff --git a/sympy/utilities/iterables.py b/sympy/utilities/iterables.py
index 3b112d9748..18d80fc4e9 100644
--- a/sympy/utilities/iterables.py
+++ b/sympy/utilities/iterables.py
@@ -2253,9 +2253,8 @@ def generate_derangements(perm):
     """
     p = multiset_permutations(perm)
     indices = range(len(perm))
-    p0 = next(p)
     for pi in p:
-        if all(pi[i] != p0[i] for i in indices):
+        if all(pi[i] != perm[i] for i in indices):
             yield pi
 
 
